<html>
<head>
    <meta charset="UTF-8" content="#">
    <title>销售商品页面</title>
    <!-- 引入CSS -->
    <link rel="stylesheet" type="text/css"
          href="/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="/easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="/easyui/css/demo.css">
    <!-- 引入JS -->
    <script type="text/javascript" src="/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/easyui/themes/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="/easyui/js/validateExtends.js"></script>
    <script type="text/javascript" src="/common/js/common.js"></script>
    <script type="text/javascript" src="/common/js/order.js"></script>
    <script type="text/javascript" src="/common/js/status.js"></script>
    <script type="text/javascript">
        //DOM加载完成后执行的回调函数
        $(function () {

            var table;
            //初始化datagrid
            $('#dataList').datagrid({
                iconCls: 'icon-more',//图标
                border: true,
                collapsible: false,//是否可折叠
                fit: true,//自动大小
                method: "post",
                url: "/tech-item/getTechItems?t" + new Date().getTime(),
                idField: 'id',
                singleSelect: false,//是否单选
                rownumbers: true,//行号
                pagination: true,//分页控件
                remoteSort: false,
                columns: [
                    [
                        {field: 'chk', checkbox: true, width: 50},
                        {field: 'id', title: 'ID', width: 50},
                        {
                            field: 'status', title: '状态', width: 100,
                            formatter: function (value, row, index) {
                                return getSaleItemStatus(value);
                            }
                        },
                        {field: 'itemCode', title: '商品编码', width: 100},
                        {field: 'itemName', title: '商品名称', width: 150},
                        {field: 'unit', title: '单位', width: 50},
                        {field: 'bomPrice', title: 'Bom价格', width: 80},
                        {field: 'remark', title: '备注', width: 150},
                        {
                            field: 'createTime', title: '创建时间', width: 165,
                            formatter: function (value, row, index) {
                                return transTime(value);
                            }
                        }
                    ]
                ],
                toolbar: "#toolbar"//工具栏
            });

            //设置分页控件
            var p = $('#dataList').datagrid('getPager');
            $(p).pagination({
                pageSize: 10,//设置每页显示的记录条数,默认为10
                pageList: [10, 20, 30, 50, 100],//设置每页记录的条数
                beforePageText: '第',
                afterPageText: '页    共 {pages} 页',
                displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',
            });

            $.post("/tech-person/getTechGroupResults", {selected: false}, function (data) {
                $('#search-techGroup').combobox({
                    textField: 'content',
                    valueField: 'value',
                    panelHeight: 'auto',
                    data: data
                })
            })

            $("#tech_confirm").click(function () {
                $('#dataList').datagrid("reload");
                var selectRows = $("#dataList").datagrid("getSelections");//返回所有选中的行,当没有选中的记录时,将返回空数组
                var selectLength = selectRows.length;
                if (selectLength === 0) {
                    $.messager.alert("消息提醒", "请选择想要确认的商品哟!", "warning");
                } else {
                    $.messager.confirm("消息", "你真的打算确认吗", function (r) {
                        if (r) {
                            var status = selectRows[0].status + 1;
                            var ids = [];
                            $(selectRows).each(function (i, row) {
                                if (!(row.bomPrice == -1)) {
                                    ids[i] = row.id;//将预关闭行的id存储到数组中
                                }
                            });
                            if (ids.length == 0) {
                                $.messager.alert("消息提醒", "没有合适的商品可以确认，请重新选择!", "warning");
                                return false;
                            }
                            $.post("/sale-item/updateSaleItemStatusByIds", {ids: ids, status: status}, function (data) {
                                if (data.success) {
                                    //重新刷新页面数据
                                    $('#dataList').datagrid("reload");
                                    $('#dataList').datagrid("uncheckAll");
                                    //用户提示
                                    $.messager.alert("消息提醒", "技术确认完毕!", "info");
                                } else {
                                    $.messager.alert("消息提醒", data.msg, "warning");
                                }
                            })
                        }
                    })
                }
            });

            $("#look_bom").click(function () {
                var selectRows = $("#dataList").datagrid("getSelections");
                if (selectRows.length !== 1) {
                    $.messager.alert("消息提醒", "请单条选择想要查看的数据哟!", "warning");
                } else {
                    $("#lookBomDialog").dialog("open");
                }
            });


            $("#lookBomDialog").dialog({
                title: "查看Bom信息窗口",
                width: 820,
                height: 600,
                padding: 0,
                iconCls: "icon-house",
                modal: true,
                collapsible: false,
                minimizable: false,
                maximizable: false,
                draggable: true,
                closed: true,
                buttons: [
                    {
                        text: '关闭',
                        plain: true,
                        iconCls: 'icon-error',
                        handler: function () {
                            $("#lookBomDialog").dialog("close");//关闭添加窗口
                        }
                    }
                ],
                //打开窗口前先初始化数据
                onBeforeOpen: function () {
                    var itemCode = $("#dataList").datagrid("getSelected").itemCode;
                    $("#lookBom_dataList").datagrid({
                        iconCls: 'icon-more',//图标
                        border: true,
                        collapsible: false,//是否可折叠
                        width: 800,
                        height: 500,
                        method: "post",
                        url: "/tech-bom/lookTechBomsByItemCode?itemCode=" + itemCode,
                        idField: 'id',
                        singleSelect: false,//是否单选
                        rownumbers: true,//行号
                        remoteSort: false,
                        pagination: true,
                        columns: [
                            [
                                {field: 'chk', checkbox: true, width: 50},
                                {field: 'thingCode', title: '物料编码', width: 150, sortable: true},
                                {field: 'thingName', title: '物料描述', width: 200, sortable: true},
                                {field: 'useCnt', title: '用量', width: 50, sortable: true},
                                {field: 'unit', title: '单位', width: 50, sortable: true},
                                {field: 'remark', title: '备注', width: 100, sortable: true},
                            ]
                        ]
                    });
                }
            });

            //设置分页控件
            var p = $('#lookBom_dataList').datagrid('getPager');
            $(p).pagination({
                pageSize: 10,//设置每页显示的记录条数,默认为10
                pageList: [10, 20, 30, 50, 100],//设置每页记录的条数
                beforePageText: '第',
                afterPageText: '页    共 {pages} 页',
                displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',
            });

            //学生与班级名搜索按钮的监听事件(将其值返回给Controller)
            $("#search-btn").click(function () {
                $('#dataList').datagrid('load', {
                    itemName: $('#search-itemName').textbox('getValue'),//获取商品名称
                    itemCode: $('#search-itemCode').textbox('getValue'),//获取商品编码
                    techGroup: $('#search-techGroup').combobox('getValue')
                });
            });


        });
    </script>
</head>
<body>

<!-- 学生列表信息 -->
<table id="dataList" cellspacing="0" cellpadding="0"></table>
<!-- 工具栏 -->
<div id="toolbar">
    <!-- 学生,班级名搜索域 -->
    <div style="margin-left: 10px;">

        <div style="float: left;"><a id="tech_confirm" href="javascript:" class="easyui-linkbutton"
                                     data-options="iconCls:'icon-add',plain:true">确认商品</a></div>
        <div style="float: left;" class="datagrid-btn-separator"></div>

        <div style="float: left;"><a id="look_bom" href="javascript:" class="easyui-linkbutton"
                                     data-options="iconCls:'icon-add',plain:true">查看商品Bom</a></div>
        <div style="float: left;" class="datagrid-btn-separator"></div>

        <!-- 商品名称搜索框 -->
        <a href="javascript:" class="easyui-linkbutton"
           data-options="iconCls:'icon-user-student',plain:true">技术组</a>
        <select id="search-techGroup" class="easyui-combobox" style="width: 250px">
        </select>

        <a href="javascript:" class="easyui-linkbutton"
           data-options="iconCls:'icon-user-student',plain:true">商品编码</a>
        <input id="search-itemCode" class="easyui-textbox"/>
        <a href="javascript:" class="easyui-linkbutton"
           data-options="iconCls:'icon-user-student',plain:true">商品名称</a>
        <input id="search-itemName" class="easyui-textbox"/>
        <!-- 搜索按钮 -->
        <a id="search-btn" href="javascript:" class="easyui-linkbutton"
           data-options="iconCls:'icon-search',plain:true">搜索</a>
    </div>
</div>

<div id="lookBomDialog">
    <table id="lookBom_dataList"></table>
</div>

</body>
</html>